package erfgame.core.j3d;

import java.net.URL;

import javax.media.j3d.BranchGroup;

import com.sun.j3d.loaders.Loader;
import com.sun.j3d.loaders.Scene;

public class LoaderBranchGroupFactory implements BranchGroupFactory {

	private Loader loader;
	private URL resource;
	
	public LoaderBranchGroupFactory( Loader loader, String path ) {
		this( loader, LoaderBranchGroupFactory.class.getResource(path) );
	}
	
	public LoaderBranchGroupFactory( Loader loader, URL resource ) {
		this.loader = loader;
		this.resource = resource;
	}
	
	@Override
	public BranchGroup createBranchGroup() throws Exception {
		Scene scene = loader.load(this.resource);
		// TODO : we probably want to clone this
		// TODO : do we need to set any values on the group (mutable)
		return scene.getSceneGroup();
	}

}
